import type { SaleOrderForm, SaleOrderQuery, SaleOrderVO } from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询销售订单列表
 * @param params
 * @returns 销售订单列表
 */
export function saleOrderList(params?: SaleOrderQuery) {
  return requestClient.get<PageResult<SaleOrderVO>>('/hm/saleOrder/list', {
    params,
  });
}

/**
 * 导出销售订单列表
 * @param params
 * @returns 销售订单列表
 */
export function saleOrderExport(params?: SaleOrderQuery) {
  return commonExport('/hm/saleOrder/export', params ?? {});
}

/**
 * 查询销售订单详情
 * @param saleId id
 * @returns 销售订单详情
 */
export function saleOrderInfo(saleId: ID) {
  return requestClient.get<SaleOrderVO>(`/hm/saleOrder/${saleId}`);
}

/**
 * 新增销售订单
 * @param data
 * @returns void
 */
export function saleOrderAdd(data: SaleOrderForm) {
  return requestClient.postWithMsg<void>('/hm/saleOrder', data);
}

/**
 * 更新销售订单
 * @param data
 * @returns void
 */
export function saleOrderUpdate(data: SaleOrderForm) {
  return requestClient.putWithMsg<void>('/hm/saleOrder', data);
}

/**
 * 销售订单退货
 * @param data
 * @returns void
 */
export function orderReturns(data: SaleOrderForm) {
  return requestClient.putWithMsg<void>('/hm/saleOrder/orderReturns', data);
}

/**
 * 删除销售订单
 * @param saleId id
 * @returns void
 */
export function saleOrderRemove(saleId: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/hm/saleOrder/${saleId}`);
}
